add_library(zeno_cgmesh SHARED)
target_include_directories(zeno_cgmesh PRIVATE .)

find_package(Eigen3 REQUIRED)
target_link_libraries(zeno_cgmesh PRIVATE Eigen3::Eigen)

option(ZENO_CGMESH_WITH_VOROXX "Build with Voro++ nodes" ON)
if (ZENO_CGMESH_WITH_VOROXX)
    target_sources(zeno_cgmesh PRIVATE VoronoiFracture.cpp PrimitiveVoronoi.cpp)
    add_subdirectory(voro)
    target_link_libraries(zeno_cgmesh PRIVATE voro++)
endif()

option(ZENO_CGMESH_WITH_MESHFIX "Build with MeshFix nodes" ON)
if (ZENO_CGMESH_WITH_MESHFIX)
    target_sources(zeno_cgmesh PRIVATE PrimitiveMeshingFix.cpp)
    add_subdirectory(meshfix)
    target_include_directories(zeno_cgmesh PRIVATE meshfix/JMeshExt-1.0alpha_src/include meshfix/JMeshExt-1.0alpha_src/JMeshLib-1.2/include)
    add_definitions(-DUSE_FORTRAN_BLAS)
    if(APPLE)
      set(CMAKE_CXX_LINK_FLAGS "-framework Accelerate")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
    endif()
    target_link_libraries(zeno_cgmesh PRIVATE meshfix jmesh jmeshext nl superlu)
    if (UNIX)
        target_link_libraries(zeno_cgmesh PRIVATE blas lapack)
    else()
        find_package(OpenBLAS CONFIG REQUIRED)
        find_package(LAPACK CONFIG REQUIRED)
        target_link_libraries(zeno_cgmesh PRIVATE OpenBLAS::OpenBLAS)
        target_link_libraries(zeno_cgmesh PRIVATE ${LAPACK_LIBRARIES})
    endif()
endif()

option(ZENO_CGMESH_WITH_LIBIGL "Build with LIBIGL nodes" ON)
if (ZENO_CGMESH_WITH_LIBIGL)
    #set(CMAKE_LINK_WHAT_YOU_USE TRUE)
    target_sources(zeno_cgmesh PRIVATE igl_sink.cpp igl_dummy.cpp PrimitiveBooleanOp.cpp)
	set(LIBIGL_USE_STATIC_LIBRARY    OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_CGAL              ON CACHE BOOL "EMBED")
	set(LIBIGL_WITH_COMISO            OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_EMBREE            OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_OPENGL            OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_OPENGL_GLFW       OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_OPENGL_GLFW_IMGUI OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_PNG               OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_TETGEN            OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_TRIANGLE          OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_PREDICATES        OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_XML               OFF CACHE BOOL "EMBED")
	set(LIBIGL_WITH_PYTHON            OFF CACHE BOOL "EMBED")
    add_subdirectory(libigl)
    target_link_libraries(zeno_cgmesh PRIVATE igl::core igl::cgal)
endif()

find_package(OpenMP)
if (TARGET OpenMP::OpenMP_CXX)
    message("found package: OpenMP::OpenMP_CXX")
    target_link_libraries(zeno_cgmesh PRIVATE OpenMP::OpenMP_CXX)
endif()

target_link_libraries(zeno_cgmesh PUBLIC zeno)
target_link_libraries(zeno_cgmesh PRIVATE zeno_nodep igl_cgal)
